home *** CD-ROM | disk | FTP | other *** search
- /*
- Fractal Popcorn - by John Jeppson.
-
- This source code is in the public domain.
- Written in MPW C.
-
- This program is an MPW Tool which implements Clifford A. Pickover's
- "Fractal Popcorn" as described in "Computer Recreations" by
- A.K.Dewdney in Scientific American, July 1989.
-
- From the MPW Worksheet execute:
-
- Popcorn top, left, edge
-
- where "top" and "left" are the corner of the target square and "edge"
- is its side.
-
- After the display is drawn you will hear a SysBeep. You
- may interrupt a partially completed display by clicking the
- mouse or pressing any key. You may not see any immediate
- effect, but the drawing will soon terminate with a double
- SysBeep at the end of the current inner loop.
-
- You may print the completed display by pressing "p".
-
- Return to the shell with the close box.
-
-
- Popcorn -6, -6, 12 - an overall view of the 12 unit square about
- the origin.
-
- Popcorn -3, -3, 6 - the central portion of the above. This is about
- the level of magnification of the illustration
- in Scientific American.
-
- Popcorn -2.5, -2.5, 2 - enlargements of a single "kernel".
- Popcorn -2, -2, 1
-
- */
-
- #if 0 ////////////////
- #include <Types.h>
- #include <Windows.h>
- #include <Memory.h>
- #include <Printing.h>
- #include <Fonts.h>
- #include <Resources.h>
- #include <OSUtils.h>
- #include <Math.h>
- #include <StdLib.h>
-
- #endif ///////////////
-
- void plot (double x, double y);
-
-
- #if 0
- void plot (extended x, extended y)
- #else
- void plot (double x, double y)
- #endif
- {
- short xi, yi;
- #define rint(x) ((int)x)
-
- xi = rint(x);
- yi = rint(y);
-
- MoveTo (xi, yi);
- Line (0,0);
- }
-
-
-
- #if 0
-
- void makeOffScreen() /* set up offscreen bitmap to store image */
- {
- Size sizeOfOff;
- short offRowBytes;
-
- offRowBytes = (((windowEdge - 1) / 16) + 1) * 2;
- sizeOfOff = windowEdge * offRowBytes;
-
- offScreen.baseAddr = (QDPtr) NewPtr(sizeOfOff);
- offScreen.rowBytes = offRowBytes;
- SetRect(&(offScreen.bounds), 0, 0, windowEdge, windowEdge);
- }
-
-
- void printWindow()
- {
- TPPrPort pport;
- THPrint hPrint;
- TPrStatus PrStatus;
- GrafPtr oldPort;
- Boolean notCancelled = true;
- Boolean drop;
-
- GetPort (&oldPort);
- PrOpen();
-
- SetFractEnable(true);
- SetFScaleDisable(true);
-
- hPrint = (THPrint) NewHandle(sizeof(TPrint));
- if (ResError())
- {
- printf ("Printing Error %d\n", ResError());
- SysBeep(1);
- PrClose();
- return;
- }
-
- drop = PrValidate(hPrint);
- notCancelled = PrJobDialog (hPrint);
-
- if (notCancelled)
- {
- pport = PrOpenDoc(hPrint, nil, nil);
- if ( PrError() == noErr )
- {
- PrOpenPage(pport, nil);
- if (PrError()==noErr)
- CopyBits (&offScreen, &(pport->gPort.portBits),
- &(offScreen.bounds), &(offScreen.bounds),
- srcCopy, nil);
- PrClosePage(pport);
- }
- PrCloseDoc(pport);
- }
- if ( ((**hPrint).prJob.bJDocLoop == bSpoolLoop)
- && (PrError() == noErr) )
- PrPicFile (hPrint, nil, nil, nil, &PrStatus);
-
- SetFractEnable(false);
- SetFScaleDisable(false);
-
- PrClose();
-
- SetPort (oldPort);
- }
-
-
- void mainLoop()
- {
- Boolean done = false;
- EventRecord theEvent;
- WindowPtr whichWindow;
- short part;
-
- while ( !done )
- {
- if ( GetNextEvent(everyEvent, &theEvent) )
- {
- switch ( theEvent.what )
- {
- case updateEvt:
- doUpdate(display);
- break;
-
- case mouseDown:
- part = FindWindow(theEvent.where, &whichWindow);
- if ( (whichWindow == display) && (part == inGoAway) )
- done = true;
- else
- SysBeep(1);
- break;
-
- case keyDown:
- if ( 'p' == (theEvent.message & charCodeMask) )
- printWindow();
- else
- SysBeep(1);
- break;
- }
- }
- }
- }
-
- #endif
-
-